var CreatePact = function(){
	
	var ps = new ProjectSourceDemo();
	
	
	var searchID = new Ext.form.TextField({
		fieldLabel : '客户编号',
		width : 150
	});
	var searchName = new Ext.form.TextField({
		fieldLabel : '客户名称',
		width : 150
	});
	var searchArea = new Ext.form.ComboBox( {
		fieldLabel : '所属区域',
		//hiddenName : 'type',
		store: OMS.AREA,
		mode : 'local',
		displayField : 'name',
		triggerAction : 'all',
		editable : false,
		valueField : 'id',
		typeAhead : true,
		width : 150,
		emptyText : '---请选择---',
		selectOnFocus : true
	});
	
	var btn_search = new Ext.Button({
		text : '查询',
		iconCls: 'icon-search',
		handler: function (){
			customerStore.load();
			}
	});
	var customerStore = new Ext.data.JsonStore(
			{
				url : '../customer/searchCustomer.form?status=10&timesnap=' + new Date().getTime(),
				root : 'result',
				fields : [  'id', 'CustomerName', 'Area',
							'CustomerSize', 'CustomerType', 'CustomerAddress',
							'FirstContact', 'Mobile', 'Leader', 'EmployCount',
							'CompanyPhone', 'MSN', 'Email', 'Fax','QQ',
							'ContactLike', 'Birthday', 'SecondContact',
							'SecondMobile', 'PhoneMoney', 'MailMoney', 'NetMoney',
							'SuccessTime', 'Stage', 'VsName','SALESTAGE',
							'VsManager', 'VsTime', 'VsGood', 'VsBad',
							'CreateTime','CreateBy','LastUpdateTime','LastUpdateBy'],
				listeners : {
					scope : this,
					beforeload : function(thiz) {
						thiz.baseParams = {
							searchName : searchName.getValue(),
							searchArea : searchArea.getValue(),
							stage:1
							
						};
					}
				}
			});
	
	
	var createGrid = new Ext.grid.GridPanel({
		width : 930,
		height : 250,
		store : customerStore,
		scope : this,
		listeners : {
			scope : this,
			rowmousedown : function(grid,index,e){
				var data = grid.store.getAt(index).data;
				ps.setCompValueAndDisabled(data);
		       
			}
		},
		columns : [ {header:'客户名称',width: 150,sortable: true,dataIndex:'CustomerName'},
			        {header:'所属区域',width: 100, sortable: true,dataIndex:'Area',renderer:function(value){return OMS.AREA[value];}},
			        {header:'公司规模',dataIndex:'CustomerType',renderer:function(value,row){return OMS.CUSTOMERTYPE[value];}},
			        {header:'公司地址',dataIndex:'CustomerAddress'},
			        {header:'联系人姓名',width: 170,dataIndex:'FirstContact'},
			        {header:'联系人电话',dataIndex:'Mobile'}],
       bbar:new Ext.PagingToolbar({
		 pageSize: 5,
         store: customerStore,
         displayInfo: true,
         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
         emptyMsg: "没有记录..."
       })
	});
	
	
	
	
	var pactremark = new Ext.form.TextArea({
		fieldLabel : '合同细节',
		width : 840,
		height:200
	});
	
	this.createPanel = new Ext.form.FormPanel({
		frame : true,
		width : 950,
		labelWidth : 85,
		buttons : [{text:'确定',iconCls: 'icon-accept',scope:this,
					handler:function(){
						doCreate(this.createPanel);}
				   }],
		items : [{layout:'column',defaults:{layout:'form'},
			      items:[{columnWidth:0.4,items:[searchName]},
			             {columWidth:0.3,items:[searchArea]},
			             {columnWidth:0.2,items:[btn_search]}]
				 },createGrid,ps.projectInfo,
		         {layout:'column',defaults:{layout:'form'},
		          items:[{columnWidth:0.7,items:[pactremark]}]
		        }],
	    listeners: {
	    	render: {fn:function(){customerStore.load();}}
	   		    }
	});
	//确定立项信息路径
	var addCon = new Ext.data.Connection({
		url:'../pact/addPact.form?timesnap=' + new Date().getTime(),
		method:'post'
	});
	
	var doCreate = function(dp){
		var CustomerId = ps.getCustomerId();
		if(CustomerId!=''){
			Utils.confirm2({
				msg:"是否增加？",
				width:220,
				fn:function(){
		   		Utils.request(addCon,{
				params:{
					customerID:CustomerId,
					customerName:ps.getCustomerName(),
					customerArea:ps.getCustomerArea(),
					pactType:ps.getPactType(),
					pactMoney:ps.getPactMoney(),
					pactEndDate:ps.getPactEndDate(),
					pactStartDate:ps.getPactStartDate(),
					pactName:ps.getPactName(),
					pactMoneyType:ps.getPactMoneyType(),
					pactSuccessName:ps.getPactSuccessName(),
					pactSuccessDate:ps.getPactSuccessDate(),
					pactRemark:pactremark.getValue(),
					pactstage:1
					},
				success:function(data){
					
						Utils.info("操作成功","系统提示");	
						customerStore.reload();
						db.getForm().reset();
					
				}
			  })
			}});
		}else{
			Utils.info("请选择客户","系统提示");	
		}
	};
};